package q06_convert;

public class Solution_2 {
    public String convert(String s, int numRows) {
        String result = "";
        if(numRows == 1){
            return s;
        }
        for (int j = 0; j < s.length(); j += 2 *numRows - 2){
            result += s.charAt(j);
        }

        for (int i = 1; i < numRows - 1; i++) {
            String result_bin = "";

            for (int k = i; k < s.length(); k += 2 * numRows - 2){
                result_bin += s.charAt(k);
                try {
                    result_bin += s.charAt(k + 2 * numRows - 2 * (i + 1));
                } catch (Exception ignored){

                }

            }
            result += result_bin;

        }

        for (int l = numRows - 1; l < s.length(); l += 2 *numRows - 2) {
            result += s.charAt(l);
        }

        return result;
    }
}
